package com.hnkywl.sts.action.flow.endState;

import com.hnkywl.sts.entity.htgl.Cght;
import com.hnkywl.sts.entity.htgl.Ht;
import com.hnkywl.sts.entity.jhgl.Tpwzjh;
import com.hnkywl.sts.service.htgl.CghtService;
import com.hnkywl.sts.util.ApplicationInstance;
import com.hnkywl.sts.entity.jhgl.Cgwzjh;
import com.hnkywl.sts.service.jhgl.WzjhService;
import org.jbpm.api.listener.EventListener;
import org.jbpm.api.listener.EventListenerExecution;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: jerry
 * Date: 13-5-8
 * Time: 下午2:10
 * To change this template use File | Settings | File Templates.
 */
public class EndWzjhState implements EventListener {

    @Override
    public void notify(EventListenerExecution execution) throws Exception {
        // 改变状态  ytj--->ysp
        WzjhService wzjhService = ApplicationInstance.createWzjhService();
        CghtService cghtService = ApplicationInstance.createCghtService();

        Cgwzjh wzjh = wzjhService.findWzjhDetailByProcessInstance(execution.getProcessInstance().getId());
        wzjh.setZt("ysp");
        if(wzjh.getClass().getSimpleName().equalsIgnoreCase("Tpwzjh")){
            Cght cght=cghtService.createCghtByWzjh((Tpwzjh)wzjh);
            List<Ht> cghts = new ArrayList<Ht>();
            cghts.add(cght);
            wzjh.setHtList(cghts);
        }

        wzjhService.saveCgwzjh(wzjh);
    }
}
